package tech.wisefin.track.session;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

import javax.persistence.AttributeConverter;

public class JSONArrayConverter implements AttributeConverter<JSONArray, String> {
    @Override
    public String convertToDatabaseColumn(JSONArray attribute) {
        if (attribute == null) {
            return null;
        }
        return attribute.toString();
    }

    @Override
    public JSONArray convertToEntityAttribute(String dbData) {
        if (dbData == null) {
            return null;
        }
        return JSON.parseArray(dbData);
    }
}
